<template>
  <div class="search_continer">
    <div class="search_continer_title">查询栏</div>
    <!-- 查询输入项 ----------------------------------------------------------------------------------->
    <div class="search_continer_myInput">
      <el-input v-model="queryParams.outsourceNum" placeholder="请输入申请单号" />
    </div>
    <div class="search_continer_myInput">
      <el-input v-model="queryParams.equipmentNum" placeholder="请输入设备编号" />
    </div>
    <div class="search_continer_myInput">
      <el-autocomplete v-model="queryParams.equipmentName" :fetch-suggestions="querySearchAsync"
        placeholder="请输入设备名称" />
    </div>
    <div class="search_continer_myInput">
      <el-select v-model="queryParams.repairStatus" filterable placeholder="请选择维修状态">
        <el-option v-for="(item, i) in ['待维修', '维修中', '已解决','报废']" :key="i" :label="item" :value="i">
        </el-option>
      </el-select>
    </div>
    <div class="search_continer_myInput">
      <el-select v-model="queryParams.auditStatus" filterable placeholder="请选择审核状态">
        <el-option v-for="(item, i) in ['审核中', '已通过', '已驳回']" :key="i" :label="item" :value="i">
        </el-option>
      </el-select>
    </div>
    <div class="search_continer_myInput">
      <el-select v-model="queryParams.source" filterable placeholder="请选择来源">
        <el-option v-for="(item, i) in ['新增', '设备报修', '委外新增']" :key="i" :label="item" :value="i">
        </el-option>
      </el-select>
    </div>
    <!-- -------------------------------------------------------------------------------------------->
    <el-button type="primary" icon="el-icon-search" @click="handleQueryClick">查询</el-button>
    <el-button icon="el-icon-refresh-left" @click="handleReset">重置</el-button>
  </div>
</template>

<script>
import { getbaselist } from "@/api/equipment/equipment.js";
export default {
  name: 'SearchBar',
  data () {
    return {
      restaurants: [],
      timeout: null,
      /** 查询参数 --------------------------------------------------------------------------------- */
      queryParams: {
        equipmentNum: null,
        equipmentName: null,
        outsourceNum: null,
        repairStatus: undefined,
        auditStatus: undefined,
        source: undefined
      },
    }
  },
  mounted () {
    this.getlist();
  },
  methods: {
    getlist () {
      getbaselist({ orderByColumn: 'equipmentBaseId', isAsc: 'desc' }).then((res) => {
        console.log(res);
        this.restaurants = res.data.map(item => {
          return {
            value: item.equipmentName
          }
        })
      })
    },
    querySearchAsync (queryString, cb) {
      var restaurants = this.restaurants;
      var results = queryString ? restaurants.filter(this.createStateFilter(queryString)) : restaurants;
      clearTimeout(this.timeout);
      this.timeout = setTimeout(() => {
        cb(results);
      }, 2000 * Math.random());
    },

    createStateFilter (queryString) {
      return (state) => {
        return (state.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0);
      };
    },

    handleQueryClick () {
      const eaPartInfoVo = {
        'params[equipmentNum]': this.queryParams.equipmentNum,
        'params[equipmentName]': this.queryParams.equipmentName,
        outsourceNum: this.queryParams.outsourceNum,
        'repairVo.repairStatus': this.queryParams.repairStatus,
        auditStatus: this.queryParams.auditStatus,
        'repairVo.source': this.queryParams.source
      }
      this.$emit('query_click', eaPartInfoVo)
    },

    handleReset () {
      for (const k in this.queryParams) {
        this.queryParams[k] = null
      }
      this.$emit('reset_click')
    }
  }
}
</script>
<style lang="scss" scoped>
.search_continer {
  padding: 10px;
  margin-bottom: 20px;
  display: flex;
  background-color: white;
  border-radius: 5px;

  &_title {
    line-height: 36px;
    padding: 0 20px 0 0;
    font-weight: bold;
  }

  &_myInput {
    padding-right: 20px;
  }
}
</style>
